home *** CD-ROM | disk | FTP | other *** search
/ PCGUIA 117 / PC Guia 117.iso / Software / Produtividade / Software2 / Product4 / Setup.exe / drupal-4.6.0 / modules / legacy.module < prev    next >
Encoding:
Text File  |  2005-02-12  |  6.6 KB  |  187 lines

  1. <?php
  2. // $Id: legacy.module,v 1.5 2005/02/12 09:23:06 dries Exp $
  3.  
  4. /**
  5.  * @file
  6.  * Provides legacy handlers for upgrades from older Drupal installations.
  7.  */
  8.  
  9. /**
  10.  * Implementation of hook_help().
  11.  */
  12. function legacy_help($section) {
  13.   switch ($section) {
  14.     case 'admin/modules#description':
  15.       return t('Provides legacy handlers for upgrades from older Drupal installations.');
  16.   }
  17. }
  18.  
  19. /**
  20.  * Implementation of hook_menu().
  21.  *
  22.  * Registers menu paths used in earlier Drupal versions.
  23.  */
  24. function legacy_menu($may_cache) {
  25.   $items = array();
  26.  
  27.   if ($may_cache) {
  28.     // Map "taxonomy/page/or/52,97" to "taxonomy/term/52+97".
  29.     $items[] = array('path' => 'taxonomy/page', 'title' => t('taxonomy'),
  30.       'callback' => 'legacy_taxonomy_page',
  31.       'access' => TRUE, 'type' => MENU_CALLBACK);
  32.  
  33.     // Map "taxonomy/feed/or/52,97" to "taxonomy/term/52+97/0/feed".
  34.     $items[] = array('path' => 'taxonomy/feed', 'title' => t('taxonomy'),
  35.       'callback' => 'legacy_taxonomy_feed',
  36.       'access' => TRUE, 'type' => MENU_CALLBACK);
  37.  
  38.     // Map "blog/feed/52" to "blog/52/feed".
  39.     $items[] = array('path' => 'blog/feed', 'title' => t('blog'),
  40.       'callback' => 'legacy_blog_feed',
  41.       'access' => TRUE, 'type' => MENU_CALLBACK);
  42.   }
  43.   else {
  44.     // Map "node/view/52" to "node/52".
  45.     $items[] = array('path' => 'node/view', 'title' => t('view'),
  46.       'callback' => 'drupal_goto',
  47.       'callback arguments' => array('node/'. arg(2), NULL, NULL),
  48.       'access' => TRUE, 'type' => MENU_CALLBACK);
  49.  
  50.     // Map "book/view/52" to "node/52".
  51.     $items[] = array('path' => 'book/view', 'title' => t('view'),
  52.       'callback' => 'drupal_goto',
  53.       'callback arguments' => array('node/'. arg(2), NULL, NULL),
  54.       'access' => TRUE, 'type' => MENU_CALLBACK);
  55.  
  56.     // Map "user/view/52" to "user/52".
  57.     $items[] = array('path' => 'user/view', 'title' => t('view'),
  58.       'callback' => 'drupal_goto',
  59.       'callback arguments' => array('user/'. arg(2), NULL, NULL),
  60.       'access' => TRUE, 'type' => MENU_CALLBACK);
  61.   }
  62.  
  63.   return $items;
  64. }
  65.  
  66. /**
  67.  * Menu callback; redirects users to new taxonomy page paths.
  68.  */
  69. function legacy_taxonomy_page($operation = 'or', $str_tids = '') {
  70.   if ($operation == 'or') {
  71.     $str_tids = str_replace(',', '+', $str_tids);
  72.   }
  73.   drupal_goto('taxonomy/term/'. $str_tids);
  74. }
  75.  
  76. /**
  77.  * Menu callback; redirects users to new taxonomy feed paths.
  78.  */
  79. function legacy_taxonomy_feed($operation = 'or', $str_tids = '') {
  80.   if ($operation == 'or') {
  81.     $str_tids = str_replace(',', '+', $str_tids);
  82.   }
  83.   drupal_goto('taxonomy/term/'. $str_tids .'/0/feed');
  84. }
  85.  
  86. /**
  87.  * Menu callback; redirects users to new blog feed paths.
  88.  */
  89. function legacy_blog_feed($str_uid = '') {
  90.   // if URL is of form blog/feed/52 redirect
  91.   // if URL is of form blog/feed we have to call blog_feed_last().
  92.   if (is_numeric($str_uid)) {
  93.     drupal_goto('blog/'. $str_uid .'/feed');
  94.   }
  95.   else {
  96.     module_invoke('blog', 'feed_last');
  97.   }
  98. }
  99.  
  100. /**
  101.  * Implementation of hook_filter(). Handles URL upgrades from Drupal 4.1.
  102.  */
  103. function legacy_filter($op, $delta = 0, $format = -1, $text = '') {
  104.   switch ($op) {
  105.     case 'list':
  106.       return array(t('Legacy filter'));
  107.  
  108.     case 'description':
  109.       return t('Replaces URLs from Drupal 4.1 (and lower) with updated equivalents.');
  110.  
  111.     case 'process':
  112.       return _legacy_filter_old_urls($text, $format);
  113.  
  114.     case 'settings':
  115.       return;
  116.  
  117.     default:
  118.       return $text;
  119.   }
  120. }
  121.  
  122. /**
  123.  * Rewrite legacy URLs.
  124.  *
  125.  * This is a *temporary* filter to rewrite old-style URLs to new-style
  126.  * URLs (clean URLs).  Currently, URLs are being rewritten dynamically
  127.  * (ie. "on output"), however when these rewrite rules have been tested
  128.  * enough, we will use them to permanently rewrite the links in node
  129.  * and comment bodies.
  130.  */
  131. function _legacy_filter_old_urls($text) {
  132.   if (!variable_get('rewrite_old_urls', 0)) {
  133.     return $text;
  134.   }
  135.  
  136.   global $base_url;
  137.  
  138.   $end = substr($base_url, 12);
  139.  
  140.   if (variable_get('clean_url', '0') == '0') {
  141.     // Relative URLs:
  142.  
  143.     // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
  144.     $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"?q=\\1/view/\\2/\\4", $text);
  145.  
  146.     // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
  147.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4/\\6" , $text);
  148.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2/\\4", $text);
  149.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"?q=\\2", $text);
  150.  
  151.     // Absolute URLs:
  152.  
  153.     // rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
  154.     $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/?q=\\1/view/\\2/\\4", $text);
  155.  
  156.     // rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
  157.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4/\\6" , $text);
  158.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/?q=\\2/\\4", $text);
  159.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"$end/?q=\\2", $text);
  160.   }
  161.   else {
  162.     // Relative URLs:
  163.  
  164.     // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
  165.     $text = eregi_replace("\"(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "\"\\1/view/\\2/\\4", $text);
  166.  
  167.     // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
  168.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4/\\6", $text);
  169.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2/\\4", $text);
  170.     $text = ereg_replace("\"module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "\"\\2", $text);
  171.  
  172.     // Absolute URLs:
  173.  
  174.     // Rewrite 'node.php?id=<number>[&cid=<number>]' style URLs:
  175.     $text = eregi_replace("$end/(node)\.php\?id=([[:digit:]]+)(&cid=)?([[:digit:]]*)", "$end/\\1/view/\\2/\\4", $text);
  176.  
  177.     // Rewrite 'module.php?mod=<name>{&<op>=<value>}' style URLs:
  178.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4/\\6", $text);
  179.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2/\\4", $text);
  180.     $text = ereg_replace("$end/module\.php\?(&?[[:alpha:]]+=([[:alnum:]]+))", "$end/\\2", $text);
  181.   }
  182.  
  183.   return $text;
  184. }
  185.  
  186. ?>
  187.